package com.jeethink.erp.pile.controller;

import java.util.List;

import com.jeethink.erp.commodity.domain.TbCommodity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.erp.pile.domain.TbStockPile;
import com.jeethink.erp.pile.service.ITbStockPileService;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.common.core.page.TableDataInfo;

/**
 * 库存Controller
 * 
 * @author ypr
 * @date 2021-05-26
 */
@RestController
@RequestMapping("/erp/pile")
public class TbStockPileController extends BaseController
{
    @Autowired
    private ITbStockPileService tbStockPileService;

    /**
     * 查询库存列表
     */
    @PreAuthorize("@ss.hasPermi('erp:pile:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbStockPile tbStockPile)
    {
        startPage();
        List<TbStockPile> list = tbStockPileService.selectTbStockPileList(tbStockPile);
        return getDataTable(list);
    }

    /**
     * 导出库存列表
     */
    @PreAuthorize("@ss.hasPermi('erp:pile:export')")
    @Log(title = "库存", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbStockPile tbStockPile)
    {
        List<TbStockPile> list = tbStockPileService.selectTbStockPileList(tbStockPile);
        ExcelUtil<TbStockPile> util = new ExcelUtil<TbStockPile>(TbStockPile.class);
        return util.exportExcel(list, "pile");
    }

    /**
     * 获取库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:pile:query')")
    @GetMapping(value = "/{stockPileId}")
    public AjaxResult getInfo(@PathVariable("stockPileId") Long stockPileId)
    {
        return AjaxResult.success(tbStockPileService.selectTbStockPileById(stockPileId));
    }

    /**
     * 新增库存
     */
    @PreAuthorize("@ss.hasPermi('erp:pile:add')")
    @Log(title = "库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbStockPile tbStockPile)
    {
        return toAjax(tbStockPileService.insertTbStockPile(tbStockPile));
    }

    /**
     * 修改库存
     */
    @PreAuthorize("@ss.hasPermi('erp:pile:edit')")
    @Log(title = "库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbStockPile tbStockPile)
    {
        return toAjax(tbStockPileService.updateTbStockPile(tbStockPile));
    }

    /**
     * 删除库存
     */
    @PreAuthorize("@ss.hasPermi('erp:pile:remove')")
    @Log(title = "库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stockPileIds}")
    public AjaxResult remove(@PathVariable Long[] stockPileIds)
    {
        return toAjax(tbStockPileService.deleteTbStockPileByIds(stockPileIds));
    }


}
